import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { PhotoDeliveryApi } from '#/api/wedding/photodelivery';

import { z } from '#/adapter/form';
import {
    DICT_Wedding_TYPE,
    getDictOptions,
    getRangePickerDefaultProps,
} from '#/utils';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'deliveryId',
      label: '交付ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入交付ID',
      },
    },
    {
      fieldName: 'bookingId',
      label: '预约ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入预约ID',
      },
    },
    {
      fieldName: 'photoUrl',
      label: '照片URL列表(JSON)',
      component: 'Input',
      componentProps: {
        placeholder: '请输入照片URL列表(JSON)',
      },
    },
    {
      fieldName: 'deliveryDate',
      label: '交付日期',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'status',
      label: '交付状态',
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_Wedding_TYPE.HandCardTypeStatus.toUpperCase(), 'string'),
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'deliveryId',
      label: '交付ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入交付ID',
      },
    },
    {
      fieldName: 'bookingId',
      label: '预约ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入预约ID',
      },
    },
    {
      fieldName: 'photoUrl',
      label: '照片URL列表(JSON)',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入照片URL列表(JSON)',
      },
    },
    {
      fieldName: 'deliveryDate',
      label: '交付日期',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'status',
      label: '交付状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_Wedding_TYPE.HandCardTypeStatus.toUpperCase(), 'string'),
        placeholder: '请选择交付状态',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<PhotoDeliveryApi.PhotoDelivery>['columns'] {
  return [
    {
      field: 'id',
      title: '',
      minWidth: 120,

    },
    {
      field: 'deliveryId',
      title: '交付ID',
      minWidth: 120,

    },
    {
      field: 'bookingId',
      title: '预约ID',
      minWidth: 120,

    },
    {
      field: 'photoUrl',
      title: '照片URL列表(JSON)',
      minWidth: 120,

    },
    {
      field: 'deliveryDate',
      title: '交付日期',
      minWidth: 120,

    },
    {
      field: 'status',
      title: '交付状态',
      minWidth: 120,

    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}

